grammar trial;

options {
  language = Java;
}

@header {
package com.plt.w2w;
import java.util.Map;
import java.util.HashMap;
import java.io.*;
}

@lexer::header {
package com.plt.w2w;
}

lines returns [String val]
  :
  line l1=lines
  {
    $val = $line.val + "\n" + $l1.val;
  }
  |
  { $val = "" }
  ;
  
line returns [String val]
:
   'assignmentStatement'
   {
    $val = $assignmentStatement.val;
   }
    | 'for each ' GARMENT ' in the ' WARDROBET  LEFTCURLY lines RIGHTCURLY
    {
      $val = "for ( Garment " + $variableName.text + ": garmentArrayList ) {\n" + $block.val + "}";
    }
    | IF LEFTPARAN expr RIGHTPARAN LEFTCURLY lines RIGHTCURLY optional_tail
    | REJTOK ENDOFSTMT
    {
      $val = "";
    }
  | RETTOK IDENTIFIER ENDOFSTMT
  ;
  
optional_tail: ELSE LEFTCURLY lines RIGHTCURLY  ;
  
expr: 'expr';

GARMENT: 'garment';

WARDROBET: 'wardrobe';

RETTOK : 'return';

REJTOK: 'reject';

AND: 'and';

OR: 'or';  

IF: 'if';

ELSE: 'else';

value  :  IDENTIFIER  ;

variableName  :  IDENTIFIER  ;

LEFTPARAN  :  '('  ;

RIGHTPARAN  :  ')'  ;

LEFTCURLY  :  '{'  ;

RIGHTCURLY  :  '}'  ;

EXPR    :    'expr'    ;

DATE  :  ('0'| '1')('0'..'9') ('\/') ('0'..'3') ('0'..'9')  ;

TIME  :  ('0'..'2') ('0'..'9') (':') ('0'..'5') ('0'..'9')  ;

CONDITIONAL_OP  :  ( '==' | '!=' | '<' | '>' | '<=' | '>=')  ;

IDENTIFIER  :  ('a'..'z'| 'A'..'Z')('a'..'z'| 'A'..'Z'| '0'..'9')*  ;

NUMBER  :  ('0'..'9')+  ;

QUOTE : '\"';

ENDOFSTMT  :  ';'  ;

DELIMITER  :  '.'  ;
  
WS : (' ' | '\t' | '\n'  | '\r' | '\f ')+ {$channel=HIDDEN;};